/*
 * Ch 5.1
 */ 
import java.lang.*;
class BitDemo {
    public static int updateBits (int n, int m, int i, int j) {
		int max = ~0; // 11111...1111
		
		// 1111....j00000i..1111
		int leftj = max - ( ( 1 << j) -1 ); //1111..0000
		int righti = (1<<i) - 1; // 01111
		int mask = leftj|righti;
		return (n & mask) | (m << i);
	} 
	public static void main(String[] args) {
		// int n = 1024; //0b only in SE7
		int n = Integer.parseInt( "10000000000", 2 ); //decimal to binary
		int m = 21;
		System.out.println(Integer.toBinaryString(updateBits(n,m,2,6)));
     }
}